package com.example.demo.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class Config implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludes=new ArrayList<String>() {{
            add("/editor.md/**");
            add("/css/**");
            add("/js/**");
            add("/img/**");  //放行img目录下所有文件
            add("/user/login");//登陆页
            add("/user/reg");//注册页
            add("/**/*.html");
            add("art/detail");//查看文章详情接口
            add("/art/list"); //文章分页接口
        }};registry.addInterceptor(loginInterceptor)
              .addPathPatterns("/**")
                .excludePathPatterns(excludes);
    }
}
